package com.example.houtai.service.impl;

import com.example.houtai.entity.SysRegion;
import com.example.houtai.mapper.SysRegionMapper;
import com.example.houtai.service.ISysRegionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.org.dto.SysRegionDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地区表 服务实现类
 * </p>
 *
 * @author 龚梦
 * @since 2021-03-24
 */
@Service
public class SysRegionServiceImpl extends ServiceImpl<SysRegionMapper, SysRegion> implements ISysRegionService {

    @Autowired
    private SysRegionMapper regionMapper;

    @Override
    public List<SysRegionDto> selectregion() {
        List<SysRegionDto> list=regionMapper.selectregion(1,1);
        this.getnext(list);
        return list;
    }



    private void getnext(List<SysRegionDto> list) {
        for (SysRegionDto region : list) {
            System.out.println(region);
            List<SysRegionDto> newlist=regionMapper.selectregion(region.getRegionId(),region.getRegionLevel()+1);
            if (newlist.size()>0){
                this.getnext(newlist);
                region.setSysRegionDtoList(newlist);
            }
        }
    }


    @Override
    public List<SysRegion> getByparent(Integer id) {
        return regionMapper.getByparent(id);
    }

}
